package com.mes.device.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mes.common.core.utils.poi.ExcelUtil;
import com.mes.common.core.web.controller.BaseController;
import com.mes.common.core.web.domain.AjaxResult;
import com.mes.common.core.web.page.TableDataInfo;
import com.mes.common.log.annotation.Log;
import com.mes.common.log.enums.BusinessType;
import com.mes.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mes.device.domain.DeviceMaintenance;
import com.mes.device.service.IDeviceMaintenanceService;

/**
 * 设备保养Controller
 * 
 * @author itflash
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/device/maintenance")
public class DeviceMaintenanceController extends BaseController
{
    @Autowired
    private IDeviceMaintenanceService deviceMaintenanceService;

    /**
     * 查询设备保养列表
     */
    @RequiresPermissions("device:maintenance:list")
    @GetMapping("/list")
    public TableDataInfo list(DeviceMaintenance deviceMaintenance)
    {
        startPage();
        List<DeviceMaintenance> list = deviceMaintenanceService.selectDeviceMaintenanceList(deviceMaintenance);
        return getDataTable(list);
    }

    /**
     * 导出设备保养列表
     */
    @RequiresPermissions("device:maintenance:export")
    @Log(title = "设备保养", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceMaintenance deviceMaintenance)
    {
        List<DeviceMaintenance> list = deviceMaintenanceService.selectDeviceMaintenanceList(deviceMaintenance);
        ExcelUtil<DeviceMaintenance> util = new ExcelUtil<DeviceMaintenance>(DeviceMaintenance.class);
        util.exportExcel(response, list, "设备保养数据");
    }

    /**
     * 获取设备保养详细信息
     */
    @RequiresPermissions("device:maintenance:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deviceMaintenanceService.selectDeviceMaintenanceById(id));
    }

    /**
     * 新增设备保养
     */
    @RequiresPermissions("device:maintenance:add")
    @Log(title = "设备保养", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceMaintenance deviceMaintenance)
    {
        return toAjax(deviceMaintenanceService.insertDeviceMaintenance(deviceMaintenance));
    }

    /**
     * 修改设备保养
     */
    @RequiresPermissions("device:maintenance:edit")
    @Log(title = "设备保养", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceMaintenance deviceMaintenance)
    {
        return toAjax(deviceMaintenanceService.updateDeviceMaintenance(deviceMaintenance));
    }

    /**
     * 删除设备保养
     */
    @RequiresPermissions("device:maintenance:remove")
    @Log(title = "设备保养", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceMaintenanceService.deleteDeviceMaintenanceByIds(ids));
    }
}
